package com.enzo.security.controller;

import com.enzo.security.service.SecurityUserService;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class TestSecurityController {
    @Resource
    private SecurityUserService userService;



    @RequestMapping("/login")
    public UserDetails login(String username,String password) {
            UserDetails details=userService.loadUserByUsername(username);
        return details;
    }

    @GetMapping("/toLogin2")
    public String toLogin() {
        return "login";
    }

    @GetMapping("/get")
    public String get() {
        return "get";
    }

    @GetMapping("/product/{id}")
    public String getProduct(@PathVariable String id) {
        //for debug
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return "product id : " + id;
    }

    @GetMapping("/order/{id}")
    public String getOrder(@PathVariable String id) {
        //for debug
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return "order id : " + id;
    }
}
